#include"lottery_sys.h"
/*
该函数用于：对用户登录前，用户链表化(将用户文件加载成链表)
返回值：返回用户链表的头结点
无参数
 
*/
Buyer_t* load_user(void)
{
	FILE* fpi = NULL;
	Buyer_t* user_head = NULL;
	Buyer_t* tail = NULL;
	Buyer_t* cur = NULL;
	int ret = 0;
	user_head = init_user_list();					//用户链表的初始化
	tail = user_head;
	cur = (Buyer_t*)calloc(1,sizeof(Buyer_t));
	if(!cur)
	{
		return NULL;
	}
	fpi = fopen(USER_FILE,"rb");
	if(!fpi)
	{
//		printf("文件加载失败！");
		free(cur);
		return user_head;
	}
	while(1)
	{
		ret = fread(cur,sizeof(Buyer_t),1,fpi);
		if(ret < 1)
		{
			break;
		}
		//user_head_insert(user_head,cur);
		//文件读取,头插法加载用户链表
		tail -> next = cur;
		tail = cur;
		cur = (Buyer_t*)calloc(1,sizeof(Buyer_t));
		if(!cur)
		{
			return NULL;
		}
	}
	tail -> next = NULL;
	free(cur);
	fclose(fpi);
	return user_head;
}
